﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Sprout.Core.Utils
{
    public class VerifyCodeHelper
    {
        static string[] numberCodes = "0,1,2,3,4,5,6,7,8,9".Split(',');
        static string[] abcCodes = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,P,Q,R,S,T,U,V,W,X,Y,Z".Split(',');
        static string[] mixCodes = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,P,Q,R,S,T,U,V,W,X,Y,Z".Split(',');

        /// <summary>
        /// 获取数字验证码
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetNumberCode(int length = 4)
        {
            StringBuilder code = new StringBuilder();
            Random random = new Random();
            for (var i = 0; i < length; i++)
            {
                code.Append(numberCodes[random.Next(numberCodes.Length)]);
            }

            return code.ToString();
        }
        /// <summary>
        /// 获取字母验证码
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetAbcCode(int length = 4)
        {
            StringBuilder code = new StringBuilder();
            Random random = new Random();
            for (var i = 0; i < length; i++)
            {
                code.Append(abcCodes[random.Next(abcCodes.Length)]);
            }

            return code.ToString();
        }
        /// <summary>
        /// 获取混合验证码
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetMixCode(int length = 4)
        {
            StringBuilder code = new StringBuilder();
            Random random = new Random();
            for (var i = 0; i < length; i++)
            {
                code.Append(mixCodes[random.Next(mixCodes.Length)]);
            }

            return code.ToString();
        }
    }
}
